import { post, BaseRes } from "../libs/request";
import { Relevance } from "../models/enums";
import { IDingdan, IBooks, IUser } from "../models/types";
// API路径前缀
const PREFIX = "/api/dingdan";

export interface Booklist extends BaseRes {
  rows: IBooks[];
}
export interface Dingdanlist extends BaseRes {
  data: {
    list: IDingdan[];
    total: number;
  };
}
export interface Dingdan extends BaseRes {
  data: IDingdan;
}

export async function dingdan(bookIds: string[], allprice: number, value: any) {
  const { data } = await post<BaseRes>(PREFIX + "/add", {
    bookIds,
    allprice,
    ...value,
  });
  return data;
}

export async function dingdanlist(userId: string, skip: number, limit: number) {
  const { data } = await post<Dingdanlist>(PREFIX + "/list", {
    userId,
    skip,
    limit,
  });
  return data;
}

export async function booklist(bookIds: string[], token: string) {
  const { data } = await post<Booklist>(
    PREFIX + "/list/book",
    { bookIds },
    token
  );
  return data;
}

export async function datail(dingdanId: string, token: string) {
  const { data } = await post<Dingdan>(
    PREFIX + "/detail",
    { dingdanId },
    token
  );
  return data;
}

// 确认或者取消订单
export async function confirm(dingdanId: string, flag: boolean) {
  const { data } = await post<BaseRes>(PREFIX + "/confirm", {
    dingdanId,
    flag,
  });
  return data;
}

export async function sendlist(skip: number, limit: number) {
  const { data } = await post<BaseRes>(PREFIX + "/list/send", { skip, limit });
  return data;
}
